#  简单的 higher-order function

def add(x,y,f):
    return f(x)+f(y)
print(add(-5,6,abs))


# map()
def f(x):
    return x*x
r = map(f,[1,2,3,4,5,6,7,8,9])
list(r)

# reduce()   序列求和
from functools import reduce
def add(x,y):
    return x+y
reduce(add,[1,3,5,7,9])

# 首字母大写   capitalize()
def normalize_name(name):
    return name.capitalize()
input_names=['adam','LISA','barT']
output_names=list(map(normalize_name,input_names))
print(output_names)

# filter
def is_odd(n):
    return n %2 ==1
list(filter(is_odd,[1,2,3,4,5,6,7,9]))

def not_empty(s):
    return s and s.strip()
list(filter(not_empty,['A','b',None,'C',' ']))

#  sort  排序

